Task = function (input, output, description, name, initialCursorPosition) {
    this._in = input;
    this._out = output;
    this._description = typeof(description) === 'undefined' ? '' : description;
    this._name = typeof(name) === 'undefined' ? '' : name;
    this._initialCursorPosition = typeof(initialCursorPosition) === 'undefined' ? 0 : initialCursorPosition;
};

Task.prototype = {
    getInputTape:function () {
        return this._in;
    },

    getOutputTape:function () {
        return this._out;
    },

    getDescription:function () {
        return this._description;
    },

    getName:function () {
        return this._name;
    },

    getInitialCursorPosition:function () {
        return this._initialCursorPosition;
    },

    isCorrectSolution:function (tape, cursor_pos) {
        if (this._out.isClean()) {
            return tape.getLastNotDefaultCharIndex() < cursor_pos;
        } else {
            var startIndex = this._out.getFirstNotDefaultCharIndex();
            var endIndex = this._out.getLastNotDefaultCharIndex();
            for (var i = startIndex; i <= endIndex; ++i) {
                if (tape.getSymbol(cursor_pos + i - startIndex) !== this._out.getSymbol(i)) {
                    return false;
                }
            }
        }
        return true;
    }
};

function parseTask(level) {
    var alphabet = new Alphabet(level.alphabet, level.alphabet[0]);
    var input = new Tape(alphabet);
    input.fillTape(level.input, level.inp_start_index);
    var output = new Tape(alphabet);
    output.fillTape(level.output, level.inp_start_index);
    return new Task(input, output, level.descr, level.name, level.inp_start_index);
};
